# Maintainer: Alexander F. Rødseth <xyproto@archlinux.org>
# Contributor: Christopher O'Neill <milkytracker@chrisoneill.co.uk>
# Contributor: Maks Verver <maksverver@geocities.com>

pkgname=milkytracker
pkgver=1.04.00
pkgrel=2
pkgdesc='Music tracker inspired by Fast Tracker II'
arch=(loong64 x86_64)
url='https://milkytracker.titandemo.org/'
license=(GPL3)
depends=(alsa-lib lhasa rtmidi sdl2 zlib zziplib)
makedepends=(cmake jack ninja)
optdepends=('jack: JACK audio support')
options=(!strip)
source=("$pkgname-$pkgver.tar.gz::https://github.com/milkytracker/MilkyTracker/archive/v$pkgver.tar.gz")
b2sums=('374a17c3f49feef5ea485e3257679debd83f7498b53178aaabb3bbf4588b89ef7e3109c65975bcf8730e68947649c982bb919f5b5a6b98b8d4380ec81df9e047')

prepare() {
  mv MilkyTracker-$pkgver $pkgname-$pkgver

  # Remove explicit use of C++98
  sed -e '/CMAKE_CXX_STANDARD/d' -e '/CMAKE_CXX_EXTENSIONS/d' -i $pkgname-$pkgver/CMakeLists.txt
}

build() {
  cmake \
    -B build \
    -D CMAKE_INSTALL_PREFIX=/usr \
    -D CMAKE_INSTALL_LIBDIR=lib \
    -G Ninja \
    -S $pkgname-$pkgver \
    -W nodev
  ninja -C build
}

package() {
  depends+=(libasound.so librtmidi.so)

  DESTDIR="$pkgdir" ninja install -C build

  cd $pkgname-$pkgver/resources
  install -Dm644 pictures/carton.png "$pkgdir/usr/share/pixmaps/$pkgname.png"
  install -Dm644 $pkgname.desktop -t "$pkgdir/usr/share/applications/"
  install -Dm644 $pkgname.appdata "$pkgdir/usr/share/appdata/$pkgname.appdata.xml"
}
